<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/3/8
  Time: 13:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fun"%>
<html>
<head>
    <title>应用新增</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/css/select2.min.css"
          rel="stylesheet"/>
    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/js/select2.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/global.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
     <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/plugins/My97DatePicker/WdatePicker.js"></script>
			<style>
		.jqGrid_wrapper{*+margin-left:270px;}
	
		.lt,.col-sm-3,.col-sm-8{float:left}
		.form-group{*+overflow:hidden;}
		.form-group label{width:28%\9;*+width:20%;text-align:right\9;*+text-align:right;}
		.col-sm-8 .m-t2 {width:30%\9; *+width:36%;}
		.form-group .col-sm-8{width:66%\9;*+width:66%;}
		.form-group .form-control{*+width:95%;}
		.form-control{*+height:22px;}
		#sub{*+margin-right:10px;}
		.input-group .form-control{*+z-index:-1;}
		.upload{*+position:relative;}
		.btn-primary{*+position:absolute;*+left:431px;*+top:-35px;*+z-index:3;}
	</style>
</head>
<body>
<div class="col-sm-12">
    <form class="form-horizontal m-t"  id="uploadForm">
           <a id="sure" onclick="sure()" hidden="true"></a>
        <div class="form-group">
            <label class="col-sm-3  control-label">应用ID:</label>
            <div class="col-sm-8" style="text-align: center;">
                <span>自动编号，不可修改</span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>所属公司:</label>
            <div class="col-sm-8">
            <select name="agtCode" id="agtCode"></select>
        	</div>
         </div>
         
	    <div class="form-group">
               <label class="col-sm-3  control-label"><i class="require">*</i>应用状态:</label>
            <div class="col-sm-8">
                <select name="appType" class="form-control">
                    <option value="0">上架</option>
                    <option value="1">下架</option>
                </select>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>APP名称:</label>
            <div class="col-sm-8">
                <input class="form-control" name="appName" size="30"/>
            </div>
        </div>
               <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label">logo图片:</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control " name="contentLogoImg" value=""  readonly size="30"/>
                    <div class="input-group-addon upload">
                        <input class="form-control" id="uploadLogoImg" type="file" name="upload1"
                               style="position: absolute;width: 60px;opacity: 0;"/>
                        <a class="btn btn-primary ">上传</a>
                    </div>
                </div>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>Android最新版本:</label>
            <div class="col-sm-8">
                <input class="form-control" name="androidVer" id="androidVer" placeholder="格式类型如：1.2.1" size="30"/>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>Android强制更新的版本号:</label>
            <div class="col-sm-8">
                <input class="form-control" name="androidVerLimit" id="androidVerLimit" placeholder="格式类型如：1.2.1" size="30"/>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>Android更新提示:</label>
            <div class="col-sm-8">
                <input class="form-control" name="androidVerTip" id="androidVerTip" placeholder="Android提示更新时的说明" size="30"/>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>Android版本号code(低于此版本的app，会提示更新到新版本):</label>
            <div class="col-sm-8">
                <input class="form-control" name="androidVerCode" id="androidVerCode" placeholder="对应于Android版本号" size="30"/>
            </div>
       </div>
       <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label">上传Android资源:</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" name="content" readonly size="30"/>
                    <div class="input-group-addon upload">
                        <input class="form-control" id="upload" type="file" name="upload"
                               style="position: absolute;width: 60px;opacity: 0;"/>
                        <a class="btn btn-primary">上传</a>
                    </div>
                </div>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>iOS的最新版本号(低于此版本的app，会提示更新到新版本):</label>
            <div class="col-sm-8">
                <input class="form-control" name="iosVer" id="iosVer" placeholder="格式类型如：1.2.1" size="30"/>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>iOS强制更新的版本号:</label>
            <div class="col-sm-8">
                <input class="form-control" name="iosVerLimit" id="iosVerLimit" placeholder="格式类型如：1.2.1" size="30"/>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>iOS更新提示:</label>
            <div class="col-sm-8">
                <input class="form-control" name="iosVerTip" id="iosVerTip" placeholder="iOS提示更新时的说明"  size="30"/>
            </div>
        </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>iOS地址:</label>
            <div class="col-sm-8">
                <input class="form-control" name="iosUpdateUrl" id="iosUpdateUrl" placeholder=""  size="100"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>腾讯微下载地址:</label>
            <div class="col-sm-8">
                <input class="form-control" name="wxzUrl" id="wxzUrl" placeholder=""  size="100" value=""/>
            </div>
        </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>推送服务的app_id:</label>
            <div class="col-sm-8">
                <input class="form-control" name="pushAppId" size="30"/>
            </div>
        </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>推送服务的app_secret:</label>
            <div class="col-sm-8">
                <input class="form-control" name="pushAppSecret" size="30"/>
            </div>
        </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>推送服务的app_key:</label>
            <div class="col-sm-8">
                <input class="form-control" name="pushAppKey" size="30"/>
            </div>
         </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>推送服务的master_secret:</label>
            <div class="col-sm-8">
                <input class="form-control" name="pushMasterSecret" size="30"/>
            </div>
         </div>
         
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>微信公众号名称:</label>
            <div class="col-sm-8">
                <input class="form-control" name="WeChatSubscription" id="WeChatSubscription" size="30"/>
            </div>
         </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>微信公众号原始id:</label>
            <div class="col-sm-8">
                <input class="form-control" name="WeChatSubId" id="WeChatSubId" size="30"/>
            </div>
         </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>微信产品的product_id:</label>
            <div class="col-sm-8">
                <input class="form-control" name="WeChatProductId" id="WeChatProductId" size="30"/>
            </div>
         </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>微信公众号的app_id:</label>
            <div class="col-sm-8">
                <input class="form-control" name="wxAppId" size="30"/>
            </div>
         </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>微信公众号的app_secret:</label>
            <div class="col-sm-8">
                <input class="form-control" name="wxAppSecret" size="30"/>
            </div>
        </div>
         
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>微信公众号的EncodingAESKey:</label>
            <div class="col-sm-8">
                <input class="form-control" name="WeChatEncodingAESKey" id="WeChatEncodingAESKey" size="30"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>微信公众号服务器配置token:</label>
            <div class="col-sm-8">
                <input class="form-control" name="WeChatToken" id="WeChatToken" size="30"/>
            </div>
        </div>
		<div class="form-group">
               <label class="col-sm-3  control-label"><i class="require"></i>小程序:</label>
            <div class="col-sm-8">
                <select name="wxXcxId" class="form-control">
                	<c:forEach var="item" items="${xcxlist}" varStatus="status">
                	<option value="${item.sid}">${item.cName }</option>
                	</c:forEach>
                </select>
            </div>
        </div>        
        
        
    </form>
</div>
<script type="text/javascript">
	$("select").val('0');	

$(function () {
	$.post("${pageContext.request.contextPath}/admin/tagent_list.action", function (data) {
        $("#agtCode").empty();
        $("#agtCode").append("<option value=''>请选择公司</option>");
        for (var i = 0; i < data.length; i++) {
            $("#agtCode").append("<option value='" + data[i].agtCode + "'>" + data[i].agtName + "</option>");
        }
        $("#agtCode").select2({
            "placeholder": "请选择公司",
            "width": "100%"
        })
    }, "json");
	$("#upload").change(function () {
        var filename = $(this).val();
        var index = filename.lastIndexOf("\\");
        $("input[name='content']").val(filename.substring(index + 1));
    });
	
	$("#uploadLogoImg").change(function () {
        var filename = $(this).val();
        var index = filename.lastIndexOf("\\");
        $("input[name='contentLogoImg']").val(filename.substring(index + 1));
    });
        
})
    function sure(){
        	var androidVer = $("#androidVer").val();
        	var androidVerLimit = $("#androidVerLimit").val();
        	var androidVerTip = $("#androidVerTip").val();
        	var androidVerCode = $("#androidVerCode").val();
        	var iosVer = $("#iosVer").val();
        	var iosVerLimit = $("#iosVerLimit").val();
        	var iosVerTip = $("#iosVerTip").val();
        	var iosVerTip = $("#iosVerTip").val();
        	var WeChatSubscription = $("#WeChatSubscription").val();
			var WeChatSubId = $("#WeChatSubId").val();
			var WeChatProductId = $("#WeChatProductId").val();
			var WeChatEncodingAESKey = $("#WeChatEncodingAESKey").val();
			var iosUpdateUrl = $("#iosUpdateUrl").val();
        	var formData = new FormData($( "#uploadForm" )[0]); 
			if(((androidVer=='' || androidVerTip=='' || androidVerCode=='' ))&&(androidVer!='' || androidVerTip!='' || androidVerCode!='')){
				alert("Android版本填写时，必须同时填写Android版本号，Android更新提示和Android版本号code");
				return;
			}
			if(((iosVer=='' || iosVerTip=='' ))&&(iosVer!='' || iosVerTip!='' )){
				alert("iOS版本填写时，必须同时填写iOS版本号，iOS强制更新的版本号和iOS更新提示");
				return;
			}
// 			if(androidVer=='' && iosVer==''){
// 				alert("Android版本或iOS版本号，必须选填其中一个");
// 				return;
// 			}
			var reg =new RegExp("^\\d{1,9}\.\\d{1,9}\.\\d{1,9}$");
			if(androidVer!='' && !(reg.test(androidVer))){
	           	alert("Android版本号格式错误，必须含有2个小数点，小数前后都为数字");
		    	$("#sub").removeAttr("disabled");
		    	return;
	        }
			if(androidVerLimit!='' && !(reg.test(androidVerLimit))){
	           	alert("Android强制更新的版本号错误，必须含有2个小数点，小数前后都为数字");
		    	$("#sub").removeAttr("disabled");
		    	return;
	        }
			if(iosVer!='' && !(reg.test(iosVer))){
	           	alert("iOS版本号格式错误，必须含有2个小数点，小数前后都为数字");
		    	$("#sub").removeAttr("disabled");
		    	return;
	        }
			if(iosVerLimit!='' && !(reg.test(iosVerLimit))){
	           	alert("iOS强制更新的版本号错误，必须含有2个小数点，小数前后都为数字");
		    	$("#sub").removeAttr("disabled");
		    	return;
	        }
			if(!WeChatSubscription){
				alert("微信公众号名称不能为空");
				return;
			}
			if(!WeChatSubId){
				alert("微信公众号原始id不能为空");
				return;
			}
			if(!WeChatProductId){
				alert("微信产品的product_id不能为空");
				return;
			}
			if(!WeChatEncodingAESKey){
				alert("微信公众号的EncodingAESKey不能为空");
				return;
			}
			if(!WeChatToken){
				alert("微信公众号服务器配置token不能为空");
				return;
			}
        	$.ajax({  
             url: '${pageContext.request.contextPath}/admin/appstore_add.action' ,  
             type: 'POST',  
             data: formData,  
             async: false,  
             cache: false,  
             contentType: false,  
             processData: false,  
             success: function (result) {  
                  result = JSON.parse(result)
                  if (result.code == 1) {
                		var index = parent.layer.getFrameIndex(window.name);
                	  window.location.href = "${pageContext.request.contextPath}/admin/appstore_listView.action";
                      parent.layer.close(index); 
                  }else{
                  	alert(result.msg);
                  }
             },  
             error: function (returndata) {  
                 alert(returndata);  
             }  
        	});
        }
</script>
</body>
</html>
